Add a new folder and create your notebook
Python list comprehension
It's a repository of conda packages
Check your channels:
conda config --show
Check this URL: https://bioconda.github.io/
conda config --add channels conda-forge
conda config --add channels defaults
conda config --add channels r
conda config --add channels bioconda
conda config --add channels bbglab
In [6]:
[n * 2 for n in range(10) if n % 2 == 1]
Out[6]:
In [7]:
# Also a dict
{n: n * 2 for n in range(10) if n % 2 == 1}
Out[7]:
In [10]:
# Or a set
{n * 2 for n in range(10) if n % 2 == 1}
Out[10]:
In [11]:
# ITERABLE: Anything that you can use in a for is an iterable
for a in [1,2,3]:
print(a)
In [14]:
# ITERATOR: A iteration of an iterable
list_iterator = iter([1,2,3])
print(next(list_iterator))
print(next(list_iterator))
print(next(list_iterator))
In [15]:
list_iterator = iter([1,2,3])
print(next(list_iterator))
print(next(list_iterator))
print(next(list_iterator))
print(next(list_iterator))
In [19]:
[n * 2 for n in range(10) if n % 2 == 1]
Out[19]:
In [20]:
# Convert a list comprehension to a generator comprehension
generator = (n * 2 for n in range(10) if n % 2 == 1)
generator
Out[20]:
In [21]:
iterator = iter(generator)
next(iterator)
Out[21]:
In [22]:
def odd_double(size=10):
for n in range(size):
if n % 2 == 1:
yield n*2
In [24]:
generator = odd_double()
iterator = iter(generator)
next(iterator)
Out[24]:
In [26]:
list(odd_double(15))
Out[26]:
In [1]:
import bgdata, csv, gzip, os, pandas
from pprint import pprint
domains = os.path.expanduser('~/tmp/domains.tsv.gz')
# If you want to test use this:
# domains = os.path.join(bgdata.get_path('tcgi', 'oncodrivemut', '1.1'), 'ensembl75_pfam_domain_coordinates.tsv.gz')
In [2]:
%%time
df = pandas.read_csv(domains, sep='\t')
result = df[df['Ensembl Gene ID'] == 'ENSG00000261258'].head(1).to_dict(orient='records')
pprint(result)
print('\n')
In [5]:
%%time
with gzip.open(domains, 'rt') as fd:
for r in csv.DictReader(fd, delimiter='\t'):
if r['Ensembl Gene ID'] == 'ENSG00000261258':
pprint(r)
print('\n')
break
In [8]:
%%time
with gzip.open(domains, 'rt') as fd:
reader = csv.reader(fd, delimiter='\t')
header = next(reader)
for r in reader:
if r[0] == 'ENSG00000261258':
pprint({h: v for h,v in zip(header, r)})
print('\n')
break
In [9]:
%%time
with gzip.open(domains, 'rt') as fd:
header = next(fd).split('\t')
reader = csv.reader((l for l in fd if l.startswith('ENSG00000261258')), delimiter='\t')
for r in reader:
if r[0] == 'ENSG00000261258':
pprint({h: v for h,v in zip(header, r)})
print('\n')
break
import click
@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name',
help='The person to greet.')
def hello(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
for x in range(count):
click.echo('Hello %s!' % name)
if __name__ == '__main__':
hello()
And what it looks like when run:
$ python hello.py --count=3
Your name: John
Hello John!
Hello John!
Hello John!
Santa's sleigh uses a very high-precision clock to guide its movements, and the clock's oscillator is regulated by stars. Unfortunately, the stars have been stolen... by the Easter Bunny. To save Christmas, Santa needs you to retrieve all fifty stars by December 25th.
Collect stars by solving puzzles. Two puzzles will be made available on each day in the advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
Register at: http://adventofcode.com/
Solve your first puzzle!
In [ ]: